﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iLangl.Transport.Communication
{
	public class ActionResultRequestContext : BaseContext
	{
		ActionResult _actionResult = null;
		public override void SetContext(object context)
		{
			base.SetContext(context);

			if (context is ActionResult)
			{
				_actionResult = context as ActionResult;
			}
		}

		public override object GetContext()
		{
			if (_actionResult == null)
				return string.Empty;

			startDocument();
			writer.WriteStartElement("ActionResult");
			
			InitExtendedAttributes(writer, _actionResult);
			InitExtendedElements(writer, _actionResult);

			ErrorsRequestContext errorRequestContext = new ErrorsRequestContext();
			errorRequestContext.SetContext(_actionResult.Errors);
			writer.WriteStartElement("ResultValues");
			errorRequestContext.Write(writer);
			writer.WriteEndElement();

			
			foreach (string key in _actionResult.ResultValues.Keys)
			{
				writer.WriteStartElement(key);
				writer.WriteString(_actionResult.ResultValues[key].ToString());
				writer.WriteEndElement();

			}

			writer.WriteEndElement();
			return endDocument();
		}
	}
}
